home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
10,000 Great Games
/
10,000 Great Games.iso
/
Product
/
66
/
data1.cab
/
Source_Files
/
Src
/
Scroll.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-16
|
2KB
|
90 lines
#include "stdafx.h"
fix scroll_speed = (fix)0;
static fix fstart;
static cTimer scrolltimer;
void reset_scrolling()
{
// Set game area to start
game_surface->reset();
back_surface->reset();
left_surface->reset();
right_surface->reset();
fstart = 0;
scrolltimer = 0;
// Remove objects that are not on screen
update_onscreen_list();
}
void set_scroll_position(fix f)
{
// Check bounds
if (f < (fix)0)
f = 0;
else if (f > (fix)(LEVEL_SIZE - GAME_DY))
f = LEVEL_SIZE - GAME_DY;
// Set variable
fstart = f;
// Scroll to position
game_surface->start = (int)f;
if (!no_parallax)
back_surface->start = (int)f * back_surface->total_h / game_surface->total_h;
//left_surface->start = (int)f * left_surface->total_h / game_surface->total_h;
//right_surface->start = (int)f * right_surface->total_h / game_surface->total_h;
// Remove objects that are not on screen
update_onscreen_list();
}
void do_scrolling()
{
// Get highest and lowest player
int highest = game_surface->start, lowest = game_surface->start + game_surface->h;
for (cPlayer *p = players; p != 0; p = (cPlayer *)p->next)
{
if (p->y > highest)
highest = p->y;
if (p->y < lowest)
lowest = p->y;
}
highest -= game_surface->start;
lowest -= game_surface->start;
// Get new start position
fix f, dt = scrolltimer.delta();
if (lowest < NORMAL_SCROLL_ZONE)
f = fstart + dt * scroll_speed;
else
f = fstart + dt * (scroll_speed + ((fix)MAX_SCROLL_SPEED - scroll_speed) * (lowest - NORMAL_SCROLL_ZONE) / (FAST_SCROLL_ZONE - NORMAL_SCROLL_ZONE));
// Adjust scrolling if a player comes to the top of the screen
if (highest > FAST_SCROLL_ZONE)
f += highest - FAST_SCROLL_ZONE;
// Scroll
set_scroll_position(f);
}